﻿/*-----------------------------------------------
// File: BCDeadState.cs 
// Description: 渲染层，英雄对象死亡状态，死了，就什么都没了 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;

namespace Battle.View
{
    public class BCDeadState : Fsm.FsmStateMonoBase<ActorState> 
    {
        BattleCharacter bc {
            get { return this.controller as BattleCharacter; }
        }
        public BCDeadState(ActorState state, BattleCharacter ctrl) : base(state, ctrl) {
        }



        public override void Enter()
        {
            if (bc.isAlive)
            {
                bc.ClearBuff();

                PlayDead();

                //if (bc.anim.isPlaying)
                //{
                //    isPlayBeHiting = true;
                //}
                //else {
                //    isPlayBeHiting = false;
                //    PlayDead();

                //}
                BattleManager.Instance.battlePanel.ShowEnemyInfoDead(bc);
            }
            else {
                bc.HideModel();
            }
            bc.isWillDead = false;
        }

        public override void Update()
        {
            //if (isPlayBeHiting) {
            //    if (bc.anim.IsPlaying(AniName.IDLE_FIGHT) || !bc.anim.isPlaying) {
            //        PlayDead();
            //        isPlayBeHiting = false;
            //    }
            //}
        }

        public const string deadAudio = "SE_dead";

        void PlayDead() {
            if (bc.deadParticleData != null)
            {
                bc.PlayParticle(bc.deadParticleData, true);
                AudioManager.Instance.PlaySingle(deadAudio);
            }
            bc.isAlive = false;
            bc.HideModel();
        }
    }
}
